<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html style="height:100%">
    <head>
        <title>系统首页</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">


        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" type="text/css" href="resource/js/easyui/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="resource/js/easyui/themes/icon.css">
        <link rel="stylesheet" type="text/css" href="resource/js/easyui/themes/color.css">


        <script src="resource/js/easyui/jquery.min.js" type="text/javascript"></script>
        <script src="resource/js/easyui/jquery.easyui.min.js" type="text/javascript"></script>
        <!-- <script src="../resource/js/easyui/easyloader.js" type="text/javascript"></script>-->   
        <script src="resource/js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
        <script src="resource/js/common.js" type="text/javascript"></script>
        <script src="resource/js/jquery.cookie.js" type="text/javascript"></script>
        <script src="resource/js/auth.js" type="text/javascript"></script>
        <script>
          
             
             function logout(){
				     $.cookie('loginId',null);
                 document.location = "security/login.html";
             }
           function passwdModify()
           {
                 $('#ff').form("reset");
               $('#dlg').dialog('open');
           }
           /*
            * 给地址，在工作区iframe中打开。
            */
           function  openMenu(url){
               
              $('#myiframe').attr('src',url);
               
           }
           
           /*
            * 将后台菜单数据转换成easyui 树组件可用的结构
            
           function convert(rows,root){
               
               var data =[];
             
               
               for(var i=0;i<rows.length;i++){
                   var menu =  rows[i];
                   if(!root && !menu.parent || menu.parent && menu.parent.id === root){ //父为空的
                       //alert(root);
                        var node ={};
                       node.id=menu.id;
                       node.text=menu.name;
                       if(menu.url){
                           node.attributes ={url:menu.url};
                       }
                       
                       node.children = convert(rows,menu.id); //此处递归取得每一级的子节点
                       
                       data.push(node);
                       
                   }
               }
               
               return data;
           }
           */
           
           function submitForm()
           {
                var tag =  true;
                var msg ="";
                var oldpassword = $('#oldpassword').val();
                var newpassword = $('#newpassword').val();
                var newpassword2 = $('#newpassword2').val();
        
                //先检查原密码是否正确
                $.get('api/sysUser2?loginId='+c,null,function(re){
                   var p =  re.passwd;
                   var id =  re.id;
                  // alert(oldpassword);
                //   alert(p);
                   if( p !== oldpassword){
                       tag =  false;
                       msg = "原密码输入不正确";
                       
                   }
                   
                   //再检查两次新密码是否一致
               
               if(newpassword !== newpassword2){
                   tag =  false;
                   msg = "两次输入的新密码不一致";
               }
               
               
               if(!tag){
                   
                   $.messager.alert('错误',msg);
                   return ;
               }else{  //执行更新密码
                   re._method = 'put';
                   re.passwd = newpassword;
                   $.post("api/sysUser/"+id,re,function(re){
                        $('#dlg').dialog('close');
                   });
                  
               }
                 });
               
               
               
               
           }
           
           function clearForm()
           {
               $('#ff').form("reset");
           }
 
        </script>

    </head>
    <body class="easyui-layout" fit="true" style="margin-top: 0px; margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px ">


      
       
            <div data-options="region:'north'" style="height:70px;background-image: url(resource/images/bg2.jpg);">
                <h1 style="color: #00438a;float:left">&nbsp;&nbsp;软件测试管理系统</h1>
                <div style="float:right;">
                    <span>当前用户：</span><span id="loginId"></span>&nbsp;&nbsp;
                    <span><a href="#" onclick="javascript:passwdModify();">修改密码</a></span>&nbsp;&nbsp;
                    <span><a href="#" onclick="javascript:logout();"
                                                                                             >注销</a></span>&nbsp;&nbsp;</div>
            </div>
            <div data-options="region:'south',split:true" style="height:50px;">
                <p>版权所有（Ver${version})：北京东方国信科技股份有限公司   &nbsp;&nbsp;技术支持：18638217761（宋） </p>
            </div>

            <div data-options="region:'west',split:true" title="功能菜单" style="width:200px;">


<ul class="easyui-tree" id="tt" data-options="lines:true">
    
</ul>


            </div>
            <div data-options="region:'center',title:'',iconCls:'icon-ok'">
                
                <iframe  id="myiframe"  src='security/SysUser.html' frameBorder="0" scrolling="no" style="width:100%;height:100%;margin:0px;padding: 0px;" ></iframe>

            </div> 
            
            <div id="dlg" class="easyui-dialog" title="修改密码"  closed="true" data-options="iconCls:'icon-save'" style="width:400px;height:220px;padding:10px">
            
                <form id="ff" method="post">
	    	<table cellpadding="5">
	    		<tr>
	    			<td>原密码：</td>
	    			<td><input class="easyui-passwordbox" type="text"  id = "oldpassword" name="oldpassword" data-options="required:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td>新密码</td>
	    			<td><input class="easyui-passwordbox" type="text" id="newpassword" name="newpassword" data-options="required:true,"></input></td>
	    		</tr>
	    		<tr>
	    			<td>再次输入新密码</td>
	    			<td><input class="easyui-passwordbox" type="text"  id="newpassword2" name="newpassword2" data-options="required:true"></input></td>
	    		</tr>
	    		
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">确  定</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">清  空</a>
	    </div>
	    </div>
	</div>
	
            </div>
      
   <script>
       
       
        var  url =null ;
        if(c ==='admin'){
             url = 'api/menuResource/all';
        }else{
             url = 'api/menuResource2?loginId='+c;
        }
               
       
        $('#tt').tree({
            method:"get",
            url: url,
             loadFilter: function(data){
                 return convertToTree(data,null);
                },
            onClick:function(node){
                //alert(node.attribute.url)
                if(node.attributes.url){
                    openMenu(node.attributes.url);
                }
                
            }
});

            
    var n = "";//当前账号中文名称
    $.get('api/sysUser2?loginId='+c,null,function(re){
        n =  re.name;
        $('#loginId').text(n);
    });
    
   

    </script>
    </body>
   
</html>
